//
//  MeViewController.m
//  網易
//
//  Created by 赵天宇 on 16/8/22.
//  Copyright © 2016年 赵天宇. All rights reserved.
//

#import "MeViewController.h"
#import "Masonry.h"
#import "DengLuViewController.h"
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDK/ShareSDK.h>
#import "FanKuiViewController.h"
#import "ShouCangViewController.h"
@interface MeViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>{
//    头图片
    UIImageView *titleImage;
//     表格m
    UITableView *tableV;

}
@end

@implementation MeViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTitleImage];
   [self initTableV];
    [self automaticallyAdjustsScrollViewInsets];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden=YES;
}
-(void)initTitleImage{
    titleImage = [[UIImageView alloc]init];
    titleImage.userInteractionEnabled=YES;
    titleImage.backgroundColor = [UIColor redColor];
    [self.view addSubview:titleImage];
    [titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.and.right.mas_equalTo(self.view);
        make.height.mas_equalTo(250);
//        make.bottom.mas_equalTo(tableV.mas_top);
    }];
    UIButton *loginBtn = [UIButton buttonWithType:0];
    loginBtn.layer.masksToBounds=YES;
    loginBtn .userInteractionEnabled=YES;
    loginBtn.layer.cornerRadius=10;
    [loginBtn setTitle:@"邮箱/手机号登录" forState:0];
    [loginBtn addTarget:self action:@selector(denglu) forControlEvents:UIControlEventTouchUpInside];
    [loginBtn setTitleColor:[UIColor redColor] forState:0];
    loginBtn.titleLabel.font=[UIFont  systemFontOfSize:20];
    loginBtn.backgroundColor = [UIColor whiteColor];
    [titleImage addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@40);
        make.top.mas_equalTo(titleImage.mas_top).offset(80);
        make.left.mas_equalTo(titleImage).offset(100);
        make.right.mas_equalTo(titleImage).offset(-120);
    }];
    UILabel *rgLab = [[UILabel alloc]init];
    rgLab .text=@"没有账号?手机号快速注册";
    rgLab.textColor=[UIColor whiteColor];
    [titleImage addSubview:rgLab];
    [rgLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(loginBtn.mas_bottom).offset(10);
        make.left.mas_equalTo(titleImage).offset(100);
        make.right.mas_equalTo(titleImage).offset(-100);
        make.height.mas_equalTo(@20);
    }];
    UIButton *setBtn = [UIButton buttonWithType:0];
    [setBtn setTitle:@"设置" forState:0];
    [setBtn setTitleColor:[UIColor whiteColor] forState:0];
    [titleImage addSubview:setBtn];
    [setBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleImage).offset(20);
        make.height.mas_equalTo(@20);
        make.right.mas_equalTo(titleImage).offset(-20);
    }];
    UIImageView *imageSet = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    [titleImage addSubview:imageSet];
    [imageSet mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleImage).offset(20);
        make.right.mas_equalTo(setBtn.mas_left).offset(-5);
        make.height.mas_equalTo(@20);
    }];
    UIImageView *imageLeft = [[UIImageView alloc]init];
    imageLeft.image=[UIImage imageNamed:@"user_login_weixin_highlight@2x.png"];
    [titleImage addSubview:imageLeft];
    [imageLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titleImage).offset(20);
        make.top.mas_equalTo(titleImage).offset(180);
        make.height.mas_equalTo(@30);
    }];
    UIButton *labWX = [UIButton buttonWithType:0];
    [labWX setTitle:@"微信登陆" forState:0];
    [labWX setTitleColor:[UIColor whiteColor] forState:0];
    [labWX addTarget:self action:@selector(weixin) forControlEvents:UIControlEventTouchUpInside];
    [titleImage addSubview:labWX];
    [labWX mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageLeft).offset(30);
        make.top.mas_equalTo(titleImage).offset(180);
        make.height.mas_equalTo(@30);
    }];
    UIImageView *imageWB = [[UIImageView alloc]init];
    imageWB.image=[UIImage imageNamed:@"user_login_weibo_highlight@2x.png"];
    [titleImage addSubview:imageWB];
    [imageWB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(labWX.mas_right).offset(40);
        make.height.mas_equalTo(@30);
        make.top.mas_equalTo(titleImage).offset(180);
    }];
    
    UIButton *labWB = [UIButton buttonWithType:0];
    [labWB setTitle:@"微博登陆" forState:0];
    [labWB setTitleColor:[UIColor whiteColor] forState:0];
    [titleImage addSubview:labWB];
    [labWB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageWB.mas_right).offset(10);
        make.height.mas_equalTo(@30);
        make.top.mas_equalTo(titleImage).offset(180);
    }];
    UIImageView *imageQQ = [[UIImageView alloc]init];
    imageQQ.image = [UIImage imageNamed:@"user_login_qq_highlight@2x.png"];
    [titleImage addSubview:imageQQ];
    [imageQQ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(labWB.mas_right).offset(40);
        make.height.mas_equalTo(@30);
        make.top.mas_equalTo(titleImage).offset(180);
    }];
    UIButton *labQQ = [UIButton buttonWithType:0];
    [labQQ setTitle:@"QQ登陆" forState:0];
    [labQQ setTitleColor:[UIColor whiteColor] forState:0];
    [titleImage addSubview:labQQ];
    [labQQ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleImage).offset(180);
        make.left.mas_equalTo(imageQQ.mas_right).offset(10);
        make.height.mas_equalTo(@30);
    }];
    
}
-(void)denglu{
    NSLog(@"123");
    DengLuViewController *dd= [[DengLuViewController alloc]init];
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController pushViewController:dd animated:YES];
}
//微信按钮
-(void)weixin{
    [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        
    }];
}
//初始化表格
-(void)initTableV{
    [self automaticallyAdjustsScrollViewInsets];
    tableV = [[UITableView alloc]initWithFrame:CGRectZero  style:UITableViewStyleGrouped];
    tableV.delegate=self;
    tableV.dataSource=self;
    [self.view addSubview:tableV];
    tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableV.showsVerticalScrollIndicator= NO;
    [tableV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(250);
        make.left.and.right.mas_equalTo(self.view);
        make.height.mas_equalTo(self.view.frame.size.height-220);
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section==0){
        return 1;
    }else if (section==1){
        return 2;
    }else if (section==2){
        return 3;
    }else{
        return 4;
    }
    
}
-(void)lishi{
    
}
-(void)shoucang{
    ShouCangViewController *vv=[[ShouCangViewController alloc]init];
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController pushViewController:vv animated:nil];
}
-(void)jinbi{
    
}
-(void)gentie{
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString*ss=@"love";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ss];
    if(!cell){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ss];
    }
    for (UIView *vv in cell.contentView.subviews) {
        [vv removeFromSuperview];
    }
    if(indexPath.section==0){
        UIButton *btnHistory = [UIButton buttonWithType:0];
        UIButton *btnCollect = [UIButton buttonWithType:0];
        UIButton *btnGentie = [UIButton buttonWithType:0];
        UIButton *btnGold = [UIButton buttonWithType:0];
        btnHistory.frame=CGRectMake(0, 0, self.view.frame.size.width/4, self.view.frame.size.height);
        btnCollect.frame=CGRectMake(self.view.frame.size.width/4, 0, self.view.frame.size.width/4, self.view.frame.size.height);
        btnGentie.frame=CGRectMake(self.view.frame.size.width/4*2, 0, self.view.frame.size.width/4, self.view.frame.size.height);
        btnGold.frame=CGRectMake(self.view.frame.size.width/4*3, 0, self.view.frame.size.width/4, self.view.frame.size.height);
        [cell.contentView addSubview:btnHistory];
        [cell.contentView addSubview:btnCollect];
        [cell.contentView addSubview:btnGentie];
        [cell.contentView addSubview:btnGold];
        UIImageView *imageHistory = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 20, 20)];
        UIImageView *imageCollect = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+20, 10, 20, 20)];
        UIImageView *imageGentie = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*2+20, 10, 20, 20)];
        UIImageView *imageGold = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*3+20, 10, 20, 20)];
        imageHistory.image = [UIImage imageNamed:@"audionews_indexheader_recent@2x.png"];
        imageCollect.image = [UIImage imageNamed:@"user_favor_icon@2x.png"];
        imageGentie.image = [UIImage imageNamed:@"user_comment_icon@2x.png"];
        imageGold.image  = [UIImage imageNamed:@"user_coin_icon@2x.png"];
        [cell.contentView addSubview:imageHistory];
        [cell.contentView addSubview:imageCollect];
        [cell.contentView addSubview:imageGentie];
        [cell.contentView addSubview:imageGold];
        UILabel *labHistory = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, 40, 20)];
        labHistory.text=@"历史";
        labHistory.font=[UIFont systemFontOfSize:14];
        labHistory.textColor=[UIColor grayColor];
        UILabel *labCollect = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4+20, 40, 40, 20)];
        UIButton *btn = [UIButton buttonWithType:0];
        btn.frame=CGRectMake(20, 40, 40, 20);
        [btn addTarget:self action:@selector(lishi) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:btn];
        labCollect.text=@"收藏";
        labCollect.font=[UIFont systemFontOfSize:14];
        labCollect.textColor=[UIColor grayColor];
        UILabel *labGentie = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*2+20, 40,40, 20)];
        UIButton *btn_2 = [UIButton buttonWithType:0];
        btn_2.frame=CGRectMake(self.view.frame.size.width/4+20, 40, 40, 20);
        [btn_2 addTarget:self action:@selector(shoucang) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:btn_2];
        labGentie.text=@"跟贴";
        labGentie.font=[UIFont systemFontOfSize:14];
        labGentie.textColor=[UIColor grayColor];
        UILabel *labGold = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/4*3+20, 40, 40, 20)];
        UIButton *btn_3 = [UIButton buttonWithType:0];
        [btn_3 addTarget:self action:@selector(gentie) forControlEvents:UIControlEventTouchUpInside];
        btn_3.frame=CGRectMake(self.view.frame.size.width/4*2+20, 40,40, 20);
        [cell.contentView addSubview:btn_3];
        labGold.text=@"金币";
        labGold.font=[UIFont systemFontOfSize:14];
        labGold.textColor=[UIColor grayColor];
        UIButton *btn_4 = [UIButton buttonWithType:0];
        btn_4.frame=CGRectMake(self.view.frame.size.width*4+20, 40,40 , 20);
        [btn_4 addTarget:self action:@selector(jinbi) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:btn_4];
        [cell.contentView addSubview:labHistory];
        [cell.contentView addSubview:labCollect];
        [cell.contentView addSubview:labGentie];
        [cell.contentView addSubview:labGold];
        return cell;
    }else if (indexPath.section==1){
        if(indexPath.row==0){
        cell.imageView.image = [UIImage imageNamed:@""];
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text=@"我的消息";
    }else{
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.imageView.image = [UIImage imageNamed:@"user_set_icon_message@2x.png"];
        cell.textLabel.text=@"最新消息";
    }
        return cell;
    }else if (indexPath.section==2){
        if(indexPath.row==0){
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_mall@2x.png"];
            cell.textLabel.text=@"金币商城";
        }else if (indexPath.row==1){
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_mission@2x.png"];
            cell.textLabel.text=@"金币任务";
        }else{
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_message@2x.png"];
            cell.textLabel.text=@"我的钱包";
            
        }
        return cell;
    }else{
        if(indexPath.row==0){
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_message@2x.png"];
            cell.textLabel.text=@"夜间模式";
            UISwitch *open = [[UISwitch alloc]initWithFrame:CGRectMake(350, 10, 50, 40)];
            open.on=NO;
            [cell.contentView addSubview:open];
            return cell;
        }else if (indexPath.row==1){
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_message@2x.png"];
            cell.textLabel.text=@"意见反馈";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }else if (indexPath.row==2){
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_message@2x.png"];
            cell.textLabel.text=@"活动广场";
            cell.detailTextLabel.textAlignment=NSTextAlignmentRight;
            UILabel *labFuBiaoTi = [[UILabel alloc]initWithFrame:CGRectMake(220, 10, 200, 30)];
            labFuBiaoTi.textColor=[UIColor grayColor];
            labFuBiaoTi.text=@"单身狗小编晒照片招亲啦!";
            labFuBiaoTi.font = [UIFont systemFontOfSize:14];
            [cell.contentView addSubview:labFuBiaoTi];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }else{
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.imageView.image = [UIImage imageNamed:@"user_set_icon_message@2x.png"];
            cell.textLabel.text=@"离线阅读";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section==0){
        [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            
        }];
    }else if (indexPath.section==1){
        [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            
        }];
    }else if (indexPath.section==2){
        [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            
        }];
    }else if (indexPath.section==3){
        if(indexPath.row==0){
            [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
                
            }];
        }else if (indexPath.row==1){
            FanKuiViewController *vv =[[FanKuiViewController alloc]init];
            self.navigationController.navigationBarHidden=NO;
            [self.navigationController pushViewController:vv animated:YES];
            
        }else{
            [ShareSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
                
            }];
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section==0){
        return 80;
    }else{
        return 50;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

        return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if(section==0){
        return 5.0;
    }else if (section==1){
        return 5.0;
    }else if (section==2){
        return 5.0;
    }else if(section==3){
        return 0.1;
    }else{
        return 0.1;
    }
}
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    CGRect rect = titleImage.frame;
//    rect.size.height=250+scrollView.contentOffset.y;
//    titleImage.frame=CGRectMake(0, 0, self.view.frame.size.width, rect.size.height);
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
